<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title><?php echo $tituloPagina;?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  	<!--  
    <script src="Content/Scripts/jquery-1.7.2.js" type="text/javascript"></script>
    <script src="Content/Scripts/jquery-ui-1.8.20.custom.min.js" type="text/javascript"></script>
    <script src="Content/Scripts/jquery.ui.multiselect-4.3.3.js" type="text/javascript"></script>
    <script src="js/i18n/grid.locale-es.js" type="text/javascript"></script>

    <script src="Content/Scripts/jquery.jqGrid-4.3.3.min.js" type="text/javascript"></script>
    <script src="Content/Scripts/jquery.droppy.js" type="text/javascript"></script>
    <script src="Content/Scripts/jquery.validate.min.js" type="text/javascript"></script>
    <script src="Content/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
    <script src="js/fancybox.js" type="text/javascript"></script>
    <link href="Content/Site.css" rel="stylesheet" type="text/css" />
    <link href="Content/jquery.css" rel="stylesheet" type="text/css" />
    <link href="Content/themes/redmond/jquery-ui-1.8.20.custom.css" rel="stylesheet" type="text/css" />
    <link href="Content/jqGrid/jquery-ui-jqgrid.css" rel="stylesheet" type="text/css" /> 
    <link rel="stylesheet" media="screen" type="text/css" href="Content/smoothness.datepick.css" />
    <script type="text/javascript" src="js/jquery.datepick.js"></script>
    <script type="text/javascript" src="js/jquery.datepick-es.js" ></script>
    //-->
    
    <link href="Content/themes/redmond/jquery-ui-1.8.20.custom.css" rel="stylesheet" type="text/css" />
    <link href="Content/jqGrid/jquery-ui-jqgrid.css" rel="stylesheet" type="text/css" /> 
    <link href="Content/Site.css" rel="stylesheet" type="text/css" />
    <link href="Content/jquery.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" media="screen" type="text/css" href="Content/smoothness.datepick.css" />

    <script src="js/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="js/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
    <script src="js/i18n/grid.locale-es.js" type="text/javascript"></script>
    <script src="js/jquery.jqGrid.src.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/jquery.datepick.js"></script>
    <script type="text/javascript" src="js/jquery.datepick-es.js" ></script>
    <script type="text/javascript" src="js/griddefinitions.js" ></script>
        
    <script type="text/javascript">
      //<![CDATA[
      /*global $ */
      /*jslint browser: true, unparam: true */
      
      var fechadesde = Date();
      var fechahasta = Date();
      
      $(function () {
                    
        $grid = $("#gridData"),
                
        numberTemplate = gridDefinitions.numberTemplate,

        dateTemplate = gridDefinitions.dateTemplate,
        
        yesNoTemplate = gridDefinitions.yesNoTemplate;
        
        
        $grid.jqGrid(
	        	{
              url: <?php echo $paginaDatos;?>,
              <?php echo $paginaDatosParameters;?>
              
              datatype: "xml",
              mtype: "POST",
              
              colNames: <?php echo $colNames;?>,
              
              colModel: <?php echo $colModel;?>,
              
	            rowNum: <?php echo $cantItemsListado;?>,
	            rowList: <?php echo $totalItemsListado;?>,
	            pager: '#pager',

	            loadonce: true,

	            //http://stackoverflow.com/questions/13506633/paging-does-not-work-in-jqgrid

	            gridview: true,
	            rownumbers: true,
	            autoencode: true,
	            ignoreCase: true,
	            sortname: <?php echo $paginaSorting;?>,
	            viewrecords: true,
	            multiselect: false,
	            shrinkToFit: false,
	            height: '100%',
	            width: '910'
	        });
        
        $grid.jqGrid('navGrid', '#pager', 
        		{
        			refreshstate: 'current', 
        			add: <?php echo $allowEditing;?>,
        			edit: <?php echo $allowAdding;?>,
        			del: <?php echo $allowDeleting;?>,
        			search:<?php echo $allowSearching;?>
        		},
            { //Edition
            	<?php if( $allowEditing ) { ?>
            	  width:420,height:320,
                url: <?php echo $paginaAccion;?>,
                closeAfterEdit: true,
                editCaption: <?php echo $tituloEditar;?>,
                beforeShowForm: function(form) { 
                	//$('#tr_Password', form).hide(); 
                	$('#tr_Password', form).show();
                	},
                reloadAfterSubmit:true,
                editData: {
                        parent: function () {
                            var sel_id = $("#list").jqGrid('getGridParam', 'selrow');
                            var value = $("#list").jqGrid('getCell', sel_id, 'invid');
                            return value;
                        }
                    },
                afterComplete: function(){
                	  self.location.href = "<?php echo $_SERVER['PHP_SELF'];?>";
                		return [true,'']; // no error
    						}
            	<?php } ?>
            },                        // default settings for edit
            { //Adding
            	<?php if( $allowAdding ) { ?>
                width:420,height:320,
                url: <?php echo $paginaAccion;?>,
                closeAfterAdd: true,
                addCaption: <?php echo $tituloNuevo;?>,
                beforeShowForm: function(form) { $('#tr_Password', form).show(); },
                reloadAfterSubmit:true,
                editData: {
                    parent: function () {
                        var sel_id = $("#gridEntities").jqGrid('getGridParam', 'selrow');
                        var value = $("#gridEntities").jqGrid('getCell', sel_id, 'EntityName');
                        return value;
                    }
                },
                afterComplete: function(){
                	  self.location.href = "<?php echo $_SERVER['PHP_SELF'];?>";
                		return [true,'']; // no error
    						}
    						<?php } ?>
            },                        // default settings for add
            {
            		width:320,height:120,
                url: <?php echo $paginaAccion;?>,
                closeAfterSubmit: true,
                deleteCaption: <?php echo $tituloBorrar;?>,
                reloadAfterSubmit:true,
                delData: {
                    parent: function () {
                        var sel_id = $("#gridData").jqGrid('getGridParam', 'selrow');
                        var value = $("#gridData").jqGrid('getCell', sel_id, 'FieldName');
                        return value;
                    }
                },
                onclickSubmit: function (options, postdata) {

                        var selectedRowsJq = new Array();
                        var selectedRows = new Array();
                        selectedRowsJq = postdata.split(",");

                        for(var i = 0; i < selectedRowsJq.length; i++)selectedRows[i]=selectedRowsJq[i];
                        for(var i = 0; i < selectedRows.length; i++){
                            jQuery('#gridData').delRowData(selectedRows[i]);
                        }                        

                        return { myData: 'Hello'};
                    }
            },// default setting for delete
            {
              	multipleSearch:false,
              	closeAfterSearch: true,
              	closeOnEscape: true
            }
          );
                 
	        $('#del_gridData').click(function () {
	                //alert('prueba');
						}
					);
        });
       
        //]]>
    </script>    
</head>
<body>
<div class="page">
  <?php require_once('util/header.php'); ?>
    
  <div id="main">   
    <h2><?php echo $tituloPagina;?></h2>
    <div align="center">
        <table id="gridData"><tr><td></td></tr></table>
        <div id="pager"></div>
    </div>
  </div>
  
	<?php require_once('util/piepagina.php'); ?>
</div>
</body>
</html>
